package com.silas.dynflightdatatransfer;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.silas.dynflightdatatransfer.dao.FlightDynamicDataInfoMapper;
import com.silas.dynflightdatatransfer.model.entity.FlightDynamicDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.ZoneOffset;
import java.util.List;

/**
 * @Description
 * @Author zhangsong
 * @Date 2024/4/3
 **/
@RestController
@RequestMapping("/MyController")
public class MyController {

    @Autowired
    private FlightDynamicDataInfoMapper flightDataMapper;
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    private void getFlightDataInBatch() {
        // 当前时间前 3 小时
        Long start = DateUtil.date().toLocalDateTime().minusHours(24).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        // 当前时间后 3 个月
        Long end = DateUtil.date().toLocalDateTime().plusMonths(3).toInstant(ZoneOffset.of("+8")).toEpochMilli();
        LambdaQueryWrapper<FlightDynamicDataInfo> queryWrapper = new LambdaQueryWrapper<FlightDynamicDataInfo>()
                .ge(FlightDynamicDataInfo::getTimeStamp, start)
                .le(FlightDynamicDataInfo::getTimeStamp, end);

        List<FlightDynamicDataInfo> flightDataList = flightDataMapper.selectList(queryWrapper);

        System.out.printf("List size: %d\n", flightDataList.size());

        for (FlightDynamicDataInfo flightDynamicDataInfo : flightDataList) {
            int i = 10;

            if ( i-- == 0 ) {
                break;
            }

            System.out.println(flightDynamicDataInfo.getTimeStamp());
        }
    }
}
